import { defineStore } from "pinia";
import { reqProductById } from "@/api/product";
import { ElMessage } from "element-plus";

const useDetailStore = defineStore('Detail',{
    state:() => {
        return {
            goodsInfo: {}
        }
    },
    actions:{
        // 获取产品信息
        async getGoodsInfo(id:string){
            let result = await reqProductById(id)
            if(result.code == 200){
                let skuArr = result.data
                skuArr.imageList.forEach((item:any) => {
                    item.url = item.response.url
                });
                this.goodsInfo = skuArr
            }else{
                ElMessage.error(result.msg)
            }
        },
        // 加入购物车
        
    },
    getters:{
        productInfo():any{
            return this.goodsInfo || {}
        }
    }
})

export default useDetailStore